package com.zhuoyue.web.controller.system;

import com.zhuoyue.common.core.domain.AjaxResult;
import com.zhuoyue.system.domain.po.SelectTimePo;
import com.zhuoyue.system.service.ISysIndexPageDataService;
import com.zhuoyue.web.utils.OrgCodeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author zhanghui
 * 用于首页展示数据的查询
 */
@RestController
@RequestMapping("/system/indexPageData")
public class SysGetDisplayDataControl {
    @Autowired
    private OrgCodeUtils orgCodeUtils;

    @Autowired
    ISysIndexPageDataService indexPageDataService;

    @GetMapping("/yesterdayRegisterCount")
    public AjaxResult getYesterdayRegisterCount(HttpServletRequest request) {
        return AjaxResult.success(indexPageDataService.getYesterdayRegisterCount(new SelectTimePo()));
    }

    @GetMapping("/yesterdayActiveCount")
    public AjaxResult getYesterdayActiveCount(HttpServletRequest request) {
        SelectTimePo selectTimePo = new SelectTimePo();
        return AjaxResult.success(indexPageDataService.getYesterdayActiveCount(selectTimePo));
    }

    @GetMapping("/apiAccessCount")
    public AjaxResult getApiAccessCount(HttpServletRequest request) {
        return AjaxResult.success(indexPageDataService.getApiAccessCount(new SelectTimePo()));
    }

    @GetMapping("/messageCount")
    public AjaxResult getMessageCount(HttpServletRequest request) {
        int count1 = indexPageDataService.getMessageCount1(new SelectTimePo());
        int count2 = indexPageDataService.getMessageCount2(new SelectTimePo());
        int count3 = indexPageDataService.getMessageCount3(new SelectTimePo());
        int count4 = indexPageDataService.getMessageCount4(new SelectTimePo());
        int count5 = indexPageDataService.getMessageCount5(new SelectTimePo());
        int count6 = indexPageDataService.getMessageCount6(new SelectTimePo());
        return AjaxResult.success(count1 + count2 + count3 + count4 + count5 + count6);
    }

    @GetMapping("/sevenDaysRegisterCount")
    public AjaxResult getSevenDaysRegisterCount(HttpServletRequest request) {
        return AjaxResult.success(indexPageDataService.getRegisterChartData(new SelectTimePo()));
    }

    @GetMapping("/sevenDaysActiveCount")
    public AjaxResult getSevenDaysActiveCount(HttpServletRequest request) {
        return AjaxResult.success(indexPageDataService.getActiveChartData(orgCodeUtils.getOrgCode(request)));
    }

    @GetMapping("/sevenDeviceCount")
    public AjaxResult getSevenDaysDeviceCount(HttpServletRequest request) {
        return AjaxResult.success(indexPageDataService.getDeviceChartData(new SelectTimePo()));
    }

    @GetMapping("/topTenDeviceChartCount")
    public AjaxResult getTopTenDeviceChartCount(HttpServletRequest request) {
        return AjaxResult.success(indexPageDataService.getTopTenDeviceChartData(new SelectTimePo()));
    }

    @GetMapping("/productInfoCount")
    public AjaxResult getProductInfoCountCount(HttpServletRequest request) {
        return AjaxResult.success(indexPageDataService.getProductInfoCount(orgCodeUtils.getOrgCode(request)));
    }

    @GetMapping("/gatewayGeoChart")
    public AjaxResult getGatewayGeoChart(HttpServletRequest request) {
        return AjaxResult.success(indexPageDataService.getGatewayGeoChartData(new SelectTimePo()));
    }
}
